package unit2.db;
import java.io.Serializable;
import java.util.ArrayList;

import unit2.user.User;
public class Users implements  Serializable {
	private static final long serialVersionUID = -2459074558684744171L;
	private ArrayList<User>  users;
	
	public Users(){
		users =new ArrayList<User>();	
	}
		
	public void cleanTest(User user){
		for(User e:users){
			if(e.getName().equals(user.getName())){
				e.saveHistory(null);
				break;
			}
			break;
		}
	}
	
	public  void showScore(){
		for(User e:users){
			System.out.println(e.getName());
			e.showScoreOfSesions();
		}
	}
	
	public void saveFinishScore(String nameOfUser, int score){
		for(User e:users){
			if(e.getName().equals(nameOfUser)){
				e.setNewScore(score);
				break;
			}
		}
	}
	
	public void saveUser(User user){
		for(User e:users){
			System.out.print(e.getName());
			if(e.getName().equals(user.getName())){
				e.saveHistory(user.getUserHistory());
				break;
			}
		}
	}
	
	public void addUser(User userForAdding){
		users.add(userForAdding);
	}

	public int getLenght(){
		return this.users.size();
	}
	
	
	public User findUser(String name){
		for(User e: users){
			if(e.equals(name))
				return e;
		}
		return null;
	}
}

